﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<% 
    //搜索功能
    Html.RenderPartial("~/Views/Shared/search.ascx");
%> 
<!--中文书库列表-->

<div class="book_list_box w_980">
	<ul class="book_list_ul">
    	<!--1-->
        <%
        int pageno = Request["pageno"] == null ? 1 : int.Parse(Request["pageno"].ToString());//当前页
        int pagesize = 15;//单页记录数
        int count = 0;//总记录数
        int pageNumber = 0;//总页数
        IList ligg = (IList)ViewData["booklist"];
        
         %>        
        <%
            foreach (Hashtable tb in ligg)
            {
                if (tb["total"] == null)
                {
                    Response.Write("<li>");
                    Response.Write("<a href=\"/search/detail.html?id=" + tb["lb_id"] + "\" class=\"book_img_a\"><img src=\"" + BIZ.StringTool.changeImgUrl((tb["lb_cover"] == null ? "" : tb["lb_cover"].ToString())) + "\" /></a>");
                    Response.Write("<div class=\"book_list_txt\">");
                    Response.Write("<h2><a href=\"/search/detail.html?id=" + tb["lb_id"] + "\">" + tb["lb_bookName"] + "</a><strong>年龄：" + Enum.GetName(typeof(DAL.Enums.bookforAge), int.Parse(tb["lb_forAge"].ToString())).ToString().Replace("_", "") + "</strong></h2>");
                    Response.Write("<p><span></span>" + Enum.GetName(typeof(DAL.Enums.bookebook), int.Parse(tb["lb_ebook"].ToString())) + "</p>");
                    if (!string.IsNullOrEmpty(tb["lb_author"].ToString()))
                        Response.Write("<p><span>作者：</span>" + tb["lb_author"] + "</p>");
                    if (!string.IsNullOrEmpty(tb["lb_press"].ToString()))
                        Response.Write("<p><span>出版社：</span>" + tb["lb_press"] + "</p>");
                    Response.Write("<p><span>出版时间：</span>" + DateTime.Parse(tb["lb_time"].ToString()).ToString("yyyy-MM-dd") + "</p>");
                    Response.Write("</div>");
                    Response.Write("<div class=\"book_list_btn\">");
                    if (Session["user"] == null)
                    {
                        Response.Write("<a href=\"/Login/Login.html?f=" + Request.Url + "\"  class=\"btn_fav\">加入收藏</a>");
                        if (int.Parse(tb["lb_ebook"].ToString()) != (int)DAL.Enums.bookebook.电子书)
                        {
                            if (int.Parse(tb["lb_state"].ToString()) == (int)DAL.Enums.bookState.下架)
                                Response.Write("<a href=\"#\" class=\"btn_xj\">已经下架</a>");
                            else if (int.Parse(tb["lb_inventory"].ToString()) <= 0)
                                Response.Write("<a href=\"#\" class=\"btn_nobook\">没有库存</a>");
                            else
                                Response.Write("<a  href=\"/Login/Login.html?f=" + Request.Url + "\"  class=\"btn_buy\">加入购物车</a>");
                        }
                    }
                    else
                    {
                        Response.Write("<a href=\"javascript:void(0);\" onclick=\"Favorites(" + tb["lb_id"] + ")\" class=\"btn_fav\">加入收藏</a>");
                        if (int.Parse(tb["lb_ebook"].ToString()) != (int)DAL.Enums.bookebook.电子书)
                        {
                            if (int.Parse(tb["lb_state"].ToString()) == (int)DAL.Enums.bookState.下架)
                                Response.Write("<a href=\"#\" class=\"btn_xj\">已经下架</a>");
                            else if (int.Parse(tb["lb_inventory"].ToString()) <= 0)
                                Response.Write("<a href=\"#\" class=\"btn_nobook\">没有库存</a>");
                            else
                                Response.Write("<a href=\"#\" onclick=\"addLibrary(" + tb["lb_id"] + ",'" + tb["lb_bookName"] + "','" + tb["lb_translatedName"] + "'," + tb["lb_forAge"] + "," + tb["lb_price"] + "," + tb["lb_level"] + ",'" + tb["lb_cover"] + "')\" class=\"btn_buy\">加入购物车</a>");
                        }
                    }
                    Response.Write("</div>");
                    Response.Write("</li>");
                }
                else
                    count = (tb["total"] == null ? 0 : int.Parse(tb["total"].ToString()));
            }
            %>
            
            	
    </ul>
    
    <div class="pager">
        <%
            pageNumber = ((count % pagesize) == 0 ? (count / pagesize) : ((count / pagesize) + 1));
            int start = pagesize * (pageno - 1) + 1;
            if (start < 0)
                start = 0;
            int end = (start + pagesize-1);
            if (pageno == pageNumber)
            {
                if ((count % pagesize) != 0)
                {
                    end = (start + (count % pagesize) - 1);
                }
            }
        %>
            <p class="left"><%=count%> 条记录，显示第 <%=start %> 条 - 第 <%=end %> 条记录</p>
            <p class="right"><a href="/search/list.html?pageno=1" title="首页" class="a1 a1_n"></a>
            <a href="/search/list.html?pageno=<%=(pageno==1?1:pageno-1) %>" title="上一页" class="a2"></a><span>第<b><%=pageno %></b>页/共 <%=pageNumber %> 页</span>
            <a href="/search/list.html?pageno=<%=(pageno==pageNumber?pageNumber:pageno+1) %>" title="下一页" class="a3"></a><a href="/search/list.html.html?pageno=<%=pageNumber %>" title="末页" class="a4"></a>
            <select id="sPage">
            <% 
                for (int k = 1; k <= pageNumber;k++ )
                    Response.Write("<option value=\"" + k.ToString() + "\">" + k.ToString() + "</option>");
            %>
            </select></p>
            <script type="text/javascript" language="javascript">
                $(function () {
                    $("#sPage").val(<%=pageno %>);
                    $("#sPage").change(function () {
                        window.location.href = "/search/list.html.html?pageno=" + $("#sPage").val();
                    });
                })
            </script>
        </div>
    <div class="clear"></div> 
       <div id="dialog" title="图书收藏">
        目录:<select id="selDirectory" name="selDirectory">
        <option value="-1">请选择</option>
        <%
            if (Session["user"] != null)
            {
                DomainModel.UserInfo user = (DomainModel.UserInfo)Session["user"];
                BIZ.VipCenterOper v = new BIZ.VipCenterOper();
                IList l = v.getDirectoryList(user.u_id.ToString());
                foreach (Hashtable t in l)
                {
                    Response.Write("<option value=\"" + t["dl_id"] + "\">" + t["dl_name"] + "</option>");
                }
            }
             %>
        </select>
        <span id="msg" style="color:Red"></span>
        <input type="hidden" id="hid" name="hid" />
        </div>
</div>
<script type="text/javascript">
    function addLibrary(lb_id, lb_bookName, lb_translatedName, lb_forAge, lb_price, lb_level, lb_cover) {
        $.post("/search/addLibrary.html", { lb_id: lb_id, lb_bookName: lb_bookName, lb_translatedName: lb_translatedName, lb_forAge: lb_forAge, lb_price: lb_price, lb_level: lb_level, lb_cover: lb_cover }, function (dta) {
            if (dta == "have") {
                alert("该书已添加");
            }
            if (dta == "y") {
                alert("添加成功");
                window.location.reload();
            }
        });
    }
//
    $(function () {
        // Dialog			
        $('#dialog').dialog({
            autoOpen: false,
            //modal: true,//如果要加遮罩层
            width: 350,
            //close: function (event, ui) { $('#dialog').dialog("destroy") },
            buttons: {
                "确认": function () {
                    var id = $("#hid").val();
                    var dir = $("#selDirectory").val();
                    if (dir == "-1") {
                        $("#msg").text("请选择目录");
                        return false;
                    }
                    $.post("/search/saveUserSave.html", { dlid: dir, lbid: id }, function (dta) {
                        if (dta == "have") {
                            $("#msg").text("该书已添加，请不要重复添加");
                        }
                        if (dta == "y") {
                            alert("收藏成功");
                            window.location.reload();
                        }
                    });
                }
            }
        });
    });
    // Dialog Link
    function Favorites(lbid) {
        $("#hid").val(lbid);
        $('#dialog').dialog('open');
        return false;
    }
</script>
</asp:Content>
